package com.woniu.venue.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.woniu.model.Result;
import com.woniu.venue.dto.venueCertify.VenueCertifyDto;
import com.woniu.venue.form.venueCertify.CreatVenueCertifyForm;
import com.woniu.venue.form.venueCertify.LoadVenueCertifyForm;
import com.woniu.venue.form.venueCertify.RefuseVenueCertifyForm;
import com.woniu.venue.model.VenueCertify;
import com.woniu.venue.param.venueCertify.CreatVenueCertifyParam;
import com.woniu.venue.param.venueCertify.LoadVenueCertifyParam;
import com.woniu.venue.param.venueCertify.RefuseVenueCertifyParam;
import com.woniu.venue.service.VenueCertifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年07月12日
 */

@Api(tags = "场馆入驻平台")
@RestController
@RequestMapping("/venueCertify")
public class VenueCertifyController {
    @Autowired
    private VenueCertifyService venueCertifyService;
    /**
     * 生成场馆入驻申请
     */
    @PostMapping("/creat")
    @ApiOperation("生成场馆入驻申请")
    public Result creat(@RequestBody CreatVenueCertifyForm form) {
        VenueCertifyDto coachEnterDto = venueCertifyService.creat(BeanUtil.toBean(form, CreatVenueCertifyParam.class));
        return Result.getResult().setMsg("成功").setData(coachEnterDto);
    }

    /**
     * 通过申请
     */
    @GetMapping("/agree/{id}")
    public Result agree(@PathVariable("id") Integer id) {
        venueCertifyService.agree(id);
        return Result.getResult().setMsg("成功");
    }

    /**
     * 拒绝申请
     */

    @PostMapping("/refuse")
    public Result refuse(@RequestBody RefuseVenueCertifyForm form) {
        RefuseVenueCertifyParam param = BeanUtil.toBean(form, RefuseVenueCertifyParam.class);
        venueCertifyService.refuse(param);
        return Result.getResult().setMsg("成功");
    }



    /**
     * 加载所有申请
     */
    @PostMapping("/load")
    public Result load(@RequestBody LoadVenueCertifyForm form) {
        PageInfo<VenueCertifyDto> venueCertifyDtoPageInfo= venueCertifyService.load(BeanUtil.toBean(form, LoadVenueCertifyParam.class));
        return Result.getResult().setMsg("成功").setData(venueCertifyDtoPageInfo);
    }

    @ApiOperation("根据场馆id查询场馆入驻信息")
    @GetMapping("/getVenueCertifyByVenueId/{id}")
    Result getVenueCertifyByVenueId(@PathVariable("id") Integer id){
        QueryWrapper<VenueCertify> qw = new QueryWrapper<VenueCertify>().eq("venue_id", id).eq("certify_state",1);
        VenueCertify one = venueCertifyService.getOne(qw);
        return Result.getResult().setMsg("成功").setData(one);
    }

}

